package com.wenmingliang.demo3;

/**
 * 静态代理的举例
 * 特点：代理类和被代理类在编译期间，就确定下来了。不利于扩展
 */
interface ClothFactory{

    void produceCloth();
}

//代理类
class ProxyClothFactory implements  ClothFactory{

    private ClothFactory factory;//用被代理类对象进行实例化

    public ProxyClothFactory(ClothFactory factory,ClothFactory factory2) {
        this.factory = factory;
        this.factory = factory2;
    }


    @Override
    public void produceCloth() {
        System.out.println("代理工厂做一些准备工作");
        factory.produceCloth();
        System.out.println("代理工厂做一些后续的收尾工作");
    }
}

//被代理类1
class NikeClothFactory implements  ClothFactory{

    @Override
    public void produceCloth() {
        System.out.println("Nike1工厂生产一批运动服");
    }
}
//被代理类2
class NikeClothFactory2 implements ClothFactory{

    @Override
    public void produceCloth() {
        System.out.println("Nike2工厂生产一批运动服");
    }
}
public class staticProxyTest {

    public static void main(String[] args) {
        //创建被代理类的对象
        ClothFactory nike = new NikeClothFactory();
        ClothFactory nike2 = new NikeClothFactory();
        //创建代理类的对象
        ClothFactory proxyClothFactory = new ProxyClothFactory(nike,nike2);

        proxyClothFactory.produceCloth();
    }
}
